package edu.aynu.exception;

import edu.aynu.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: haha
 * @Date: 2021/5/11 22:38
 * @Description: 通用的异常处理类
 */
@ControllerAdvice
public class GlobalExceptionHandler {


    private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);


    @ExceptionHandler(value =UnReasonException.class)
    @ResponseBody
    public Result exceptionHandler(HttpServletRequest req, UnReasonException e){
        logger.info(e.getMessage());
        return Result.fail(e.getMessage());
    }
}
